home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / cvs / sprite / RCS / add.c,v < prev    next >
Encoding:
Text File  |  1991-09-10  |  7.2 KB  |  318 lines

  1. head     1.3;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.3
  10. date     91.09.10.16.12.02;  author jhh;  state Exp;
  11. branches ;
  12. next     1.2;
  13.  
  14. 1.2
  15. date     91.08.20.12.57.40;  author jhh;  state Exp;
  16. branches ;
  17. next     1.1;
  18.  
  19. 1.1
  20. date     91.07.11.12.57.46;  author jhh;  state Exp;
  21. branches ;
  22. next     ;
  23.  
  24.  
  25. desc
  26. @@
  27.  
  28.  
  29. 1.3
  30. log
  31. @add of a previously deleted file didn't work properly
  32. @
  33. text
  34. @#ifndef lint
  35. static char rcsid[] = "$Id: add.c,v 1.2 91/08/20 12:57:40 jhh Exp $";
  36. #endif !lint
  37.  
  38. /*
  39.  *    Copyright (c) 1989, Brian Berliner
  40.  *
  41.  *    You may distribute under the terms of the GNU General Public License
  42.  *    as specified in the README file that comes with the CVS 1.0 kit.
  43.  *
  44.  * Add
  45.  *
  46.  *    Adds a file or directory to the RCS source repository.  For a file,
  47.  *    the entry is marked as "needing to be added" in the user's own
  48.  *    CVS.adm directory, and really added to the repository when it is
  49.  *    committed.  For a directory, it is added at the appropriate place
  50.  *    in the source repository and a CVS.adm directory is generated
  51.  *    within the directory.
  52.  *
  53.  *    The -m option is currently the only supported option.  Some may wish
  54.  *    to supply standard "rcs" options here, but I've found that this
  55.  *    causes more trouble than anything else.
  56.  *
  57.  *    The user files or directories must already exist.  For a directory,
  58.  *    it must not already have a CVS.adm file in it.
  59.  *
  60.  *    An "add" on a file that has been "remove"d but not committed will
  61.  *    cause the file to be resurrected.
  62.  */
  63.  
  64. #include <sys/param.h>
  65. #include "cvs.h"
  66.  
  67. add(argc, argv)
  68.     int argc;
  69.     char *argv[];
  70. {
  71.     char tmp[MAXPATHLEN], message[MAXMESGLEN];
  72.     register int i;
  73.     int c, err = 0;
  74.     char *targv[5];
  75.  
  76.     if (argc == 1 || argc == -1)
  77.     add_usage();
  78.     message[0] = '\0';
  79.     optind = 1;
  80.     while ((c = getopt(argc, argv, "m:")) != -1) {
  81.     switch (c) {
  82.     case 'm':
  83.         if (strlen(optarg) >= sizeof(message)) {
  84.         warn(0, "warning: message too long; truncated!");
  85.         (void) strncpy(message, optarg, sizeof(message));
  86.         message[sizeof(message) - 1] = '\0';
  87.         } else
  88.         (void) strcpy(message, optarg);
  89.         break;
  90.     case '?':
  91.     default:
  92.         add_usage();
  93.         break;
  94.     }
  95.     }
  96.     argc -= optind;
  97.     argv += optind;
  98.     Name_Repository();
  99.     for (i = 0; i < argc; i++) {
  100.     (void) strcpy(User, argv[i]);
  101.     if (isdir(User)) {
  102.         err += add_directory(User);
  103.         continue;
  104.     }
  105.     (void) sprintf(tmp, "%s/%s", Repository, User);
  106.     if (isdir(tmp)) {
  107.         warn(0, "%s already is a directory in the repository", User);
  108.         err++;
  109.         continue;
  110.     }
  111.     (void) sprintf(Rcs, "%s/%s%s", Repository, User, RCSEXT);
  112.     Version_TS(Rcs, Tag, User);
  113.     if (VN_User[0] == '\0') {
  114.         /*
  115.          * No entry available, TS_Rcs is invalid
  116.          */
  117.         if (VN_Rcs[0] == '\0') {
  118.         /*
  119.          * There is no RCS file either
  120.          */
  121.         if (TS_User[0] == '\0') {
  122.             /*
  123.              * There is no user file either
  124.              */
  125.             warn(0, "nothing known about %s", User);
  126.             err++;
  127.         } else {
  128.             /*
  129.              * There is a user file, so build the entry for it
  130.              */
  131.             if (Build_Entry(message) != 0)
  132.             err++;
  133.         }
  134.         } else {
  135.         /*
  136.          * There is an RCS file already, so somebody else
  137.          * must've added it
  138.          */
  139.         warn(0, "%s added independently by second party", User);
  140.         err++;
  141.         }
  142.     } else if (VN_User[0] == '0' && VN_User[1] == '\0') {
  143.         /*
  144.          * An entry for a new-born file, TS_Rcs is dummy,
  145.          * but that is inappropriate here
  146.          */
  147.         warn(0, "%s has already been entered", User);
  148.         err++;
  149.     } else if (VN_User[0] == '-') {
  150.         /*
  151.          * An entry for a removed file, TS_Rcs is invalid
  152.          */
  153.         if (TS_User[0] == '\0') {
  154.         /*
  155.          * There is no user file (as it should be)
  156.          */
  157.         if (VN_Rcs[0] == '\0') {
  158.             /*
  159.              * There is no RCS file, so somebody else must've
  160.              * removed it from under us
  161.              */
  162.             warn(0, "cannot resurrect %s; RCS file removed by second party",
  163.              User);
  164.             err++;
  165.         } else {
  166.             /*
  167.              * There is an RCS file, so remove the "-" from the
  168.              * version number and restore the file
  169.              */
  170.             (void) strcpy(tmp, VN_User+1);
  171.             (void) strcpy(VN_User, tmp);
  172.             (void) sprintf(tmp, "Resurrected %s", User);
  173.             Register(User, VN_User, tmp);
  174.             targv[0] = "-f";
  175.             targv[1] = "-r";
  176.             targv[2] = VN_User;
  177.             targv[3] = argv[i];
  178.             if (update(4, targv) == 0) {
  179.             warn(0, "%s, version %s, resurrected", User, VN_User);
  180.             } else {
  181.             warn(0, "could not resurrect %s", User);
  182.             err++;
  183.             }
  184.         }
  185.         } else {
  186.         /*
  187.          * The user file shouldn't be there
  188.          */
  189.         warn(0, "%s should be removed and is still there", User);
  190.         err++;
  191.         }
  192.     } else {
  193.         /*
  194.          * A normal entry, TS_Rcs is valid, so it must already be there
  195.          */
  196.         warn(0, "%s already exists, with version number %s", User, VN_User);
  197.         err++;
  198.     }
  199.     }
  200.     Entries2Files();            /* update CVS.adm/Files file */
  201.     exit(err);
  202. }
  203.  
  204. /*
  205.  * The specified user file is really a directory.  So, let's make sure that
  206.  * it is created in the RCS source repository, and that the user's
  207.  * directory is updated to include a CVS.adm directory.
  208.  *
  209.  * Returns 1 on failure, 0 on success.
  210.  */
  211. static
  212. add_directory(dir)
  213.     char *dir;
  214. {
  215.     char cwd[MAXPATHLEN], rcsdir[MAXPATHLEN];
  216.     char message[MAXPATHLEN+100];
  217.  
  218.     if (index(dir, '/') != NULL) {
  219.     warn(0, "directory %s not added; must be a direct sub-directory", dir);
  220.     return (1);
  221.     }
  222.     if (strcmp(dir, CVSADM) == 0) {
  223.     warn(0, "cannot add a '%s' directory", CVSADM);
  224.     return (1);
  225.     }
  226.     if (getwd(cwd) == NULL) {
  227.     warn(0, "cannot get working directory: %s", cwd);
  228.     return (1);
  229.     }
  230.     if (chdir(dir) < 0) {
  231.     warn(1, "cannot chdir to %s", dir);
  232.     return (1);
  233.     }
  234.     if (isfile(CVSADM)) {
  235.     warn(0, "%s/%s already exists", dir, CVSADM);
  236.     goto out;
  237.     }
  238.     (void) sprintf(rcsdir, "%s/%s", Repository, dir);
  239.     if (isfile(rcsdir) && !isdir(rcsdir)) {
  240.     warn(0, "%s is not a directory; %s not added", rcsdir, dir);
  241.     goto out;
  242.     }
  243.     (void) sprintf(message, "Directory %s added to the repository\n", rcsdir);
  244.     if (!isdir(rcsdir)) {
  245.     int omask;
  246.     FILE *fptty;
  247.     char line[MAXLINELEN];
  248.  
  249. #ifdef sprite
  250.     fptty = open_file(getenv("TTY"), "r");
  251. #else
  252.     fptty = open_file("/dev/tty", "r");
  253. #endif
  254.     printf("Add directory %s to the repository (y/n) [n] ? ", rcsdir);
  255.     (void) fflush(stdout);
  256.     if (fgets(line, sizeof(line), fptty) == NULL ||
  257.         (line[0] != 'y' && line[0] != 'Y')) {
  258.         warn(0, "directory %s not added", rcsdir);
  259.         (void) fclose(fptty);
  260.         goto out;
  261.     }
  262.     (void) fclose(fptty);
  263.     omask = umask(2);
  264.     if (mkdir(rcsdir, 0777) < 0) {
  265.         warn(1, "cannot mkdir %s", rcsdir);
  266.         (void) umask(omask);
  267.         goto out;
  268.     }
  269.     (void) umask(omask);
  270.     (void) strcpy(Llist, " - New directory"); /* for title in message */
  271.     Update_Logfile(rcsdir, message);
  272.     }
  273.     Create_Admin(rcsdir, DFLT_RECORD);
  274.     printf("%s", message);
  275. out:
  276.     if (chdir(cwd) < 0)
  277.     error(1, "cannot chdir to %s", cwd);
  278.     return (0);
  279. }
  280.  
  281. static
  282. add_usage()
  283. {
  284.     (void) fprintf(stderr,
  285.            "%s %s [-m 'message'] files...\n", progname, command);
  286.     exit(1);
  287. }
  288. @
  289.  
  290.  
  291. 1.2
  292. log
  293. @sprite doesn't have /dev/tty
  294. @
  295. text
  296. @d2 1
  297. a2 1
  298. static char rcsid[] = "$Id: add.c,v 1.1 91/07/11 12:57:46 jhh Exp Locker: jhh $";
  299. d41 1
  300. d141 5
  301. a145 1
  302.             if (update(2, argv+i-1) == 0) {
  303. @
  304.  
  305.  
  306. 1.1
  307. log
  308. @Initial revision
  309. @
  310. text
  311. @d2 1
  312. a2 1
  313. static char rcsid[] = "$Id: add.c,v 1.10 89/11/19 23:40:28 berliner Exp $";
  314. d71 6
  315. d211 3
  316. d215 1
  317. @
  318.